$(document).ready(function(){
	
	
	$(".btn_addFundRequest").bind("click", function(e){
		accountNumber = $(this).attr("data-addFundAccountNumber");
		$("#popup_addFundRequest").fadeIn("fast", function(){
			$(".money_transaction").val("");
			$.ajax({ 
		        type: 'get', 
		        url: 'requestTransaction', 
		        data:{
		        	accountNumber : accountNumber,
		        },
		        dataType: 'json',
		        success: function (data) { 
					console.log(data, "ihi");
//					accountNumber = data.accountNumber;
					
					$(".accountNumber").html(data.accountNumber);
					$(".accountType").html(data.accountType);
					$(".accountState").html(data.accountState);
					$(".balance").html(data.balance);
					$(".fullName").html(data.idCardNumber.lastName+" "+data.idCardNumber.midName+" "+data.idCardNumber.firstName);
					$(".idCardNumber").html(data.idCardNumber.idCardNumber);
		        }
		    });
		});	
	});
	
	$("#form_addFundRequest").submit(function(e){
		e.preventDefault();
		$("#popup_addFundRequest").fadeOut();
		$("#popup_addFundConfirm").fadeIn("fast", function(){
			$.ajax({ 
		        type: 'post', 
		        url: 'addFundConfirm', 
//		        data: $("#form_addFundRequest").serialize(),
		        data: {
		        	"moneyAdd" : $("[name='moneyAdd']").val(),
		        	"accountNumber" : $("[class='accountNumber']").html(),
//		        	"accountNumber" : accountNumber,
		        },
		        dataType: 'json',
		        success: function (data) { 
					console.log(data);
					
					$(".message").html(data.message);
					$(".error").html(data.error);
					
					if(data.error != null){
						$("#btn_addFundComplete").hide();
					}else{
						$("#btn_addFundComplete").show();
					};
					
					$(".accountType").html(data.account.accountType);
					$(".accountState").html(data.account.accountState);
					$(".accountNumber").html(data.account.accountNumber);
					$(".idCardNumber").html(data.account.idCardNumber.idCardNumber);
					$(".moneyAdd").html(data.moneyTransaction);
					$(".fullName").html(data.account.idCardNumber.lastName+" "+data.account.idCardNumber.midName+" "+data.account.idCardNumber.firstName);
					$(".balance").html(data.account.balance);
					$(".moneyRemain").html(data.moneyRemain);
					
//					moneyAdd = data.moneyTransaction;
		        }
		    });
		}); 	
	});
	
	$("#btn_addFundComplete").bind("click",function(e){
		$("#popup_addFundConfirm").fadeOut();
		$("#popup_addFundComplete").fadeIn("fast", function(){
			$.ajax({ 
		        type: 'post', 
		        url: 'addFundComplete', 
//		        data: $("#form_addFundRequest").serialize(),
		        data: {
//		        	"moneyAdd" : moneyAdd,
//		        	"accountNumber" : accountNumber,
		        	"moneyAdd" : $("[class='moneyAdd']").html(),
		        	"accountNumber" : $("[class='accountNumber']").html(),
		        },
		        dataType: 'json',
		        success: function (data) { 
					$(".message").html(data.message);
					$(".error").html(data.error);
					$(".validation").html(data.validation);
				},
				error:function(e) { 
					console.log(e);
				}
		    });
		}); 	
	});
	
	$("#btn_addFundRequest_cancel").bind("click", function(e){
		$("#popup_addFundRequest").fadeOut();
	});
	
	$("#btn_addFundConfirm_cancel").bind("click", function(e){
		$("#popup_addFundConfirm").fadeOut();
	});
	
	$("#btn_addFundConfirm_close").bind("click", function(e){
		$("#popup_addFundComplete").fadeOut();
	});
});